package com.teaching.service.impl;

import com.teaching.mapper.RealTimeMapper;
import com.teaching.service.RealTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



/**
 * @author
 * @since
 */
@Service
public class RealTimeServiceImpl implements RealTimeService {

	@Autowired
	RealTimeMapper realTimeMapper;

	@Override
	public List<Map<String, Object>> query_relation_raisedhands_top10() {
		List<Map<String, Object>> list = realTimeMapper.query_relation_raisedhands_top10();
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> wind = new HashMap<String, Object>();
			wind.put("name", map.get("Relation"));
			wind.put("value", map.get("total_raisedhands"));
			result.add(wind);
		}
		return result;
	}

	@Override
	public List<Map<String, Object>> query_Class_resource_stats() {
		List<Map<String, Object>> list = realTimeMapper.query_Class_resource_stats();
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> wind = new HashMap<String, Object>();
			wind.put("name", map.get("Class"));
			wind.put("value", map.get("total_resources"));
			result.add(wind);
		}
		return result;
	}

	@Override
	public Map<String, Object> query_stage_discussion_stats() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> list = realTimeMapper.query_stage_discussion_stats();
		List<String> name = new ArrayList<String>();
		List<String> num = new ArrayList<String>();
		for (Map<String, Object> map : list) {
			name.add(map.get("StageID").toString());
			num.add(map.get("avg_discussion").toString());
		}
		result.put("name", name);
		result.put("num", num);
		return result;
	}

	@Override
	public Map<String, Object> query_grade_raisedhands_stats() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> list = realTimeMapper.query_grade_raisedhands_stats();
		List<String> name = new ArrayList<String>();
		List<String> num = new ArrayList<String>();
		for (Map<String, Object> map : list) {
			name.add(map.get("GradeID").toString());
			num.add(map.get("avg_raisedhands").toString());
		}
		result.put("name", name);
		result.put("num", num);
		return result;
	}

	@Override
	public Map<String, Object> query_topic_resources_top5() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> list = realTimeMapper.query_topic_resources_top5();
		List<String> name = new ArrayList<String>();
		List<String> num = new ArrayList<String>();
		for (Map<String, Object> map : list) {
			name.add(map.get("Topic").toString());
			num.add(map.get("total_resources").toString());
		}
		result.put("name", name);
		result.put("num", num);
		return result;
	}

	@Override
	public List<Map<String, Object>> query_parent_satisfaction_dist() {
		List<Map<String, Object>> list = realTimeMapper.query_parent_satisfaction_dist();
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> wind = new HashMap<String, Object>();
			wind.put("name", map.get("ParentschoolSatisfaction"));
			wind.put("value", map.get("student_count"));
			result.add(wind);
		}
		return result;
	}

	@Override
	public Map<String, Object> query_gradeID_resources_stats() {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Map<String, Object>> list = realTimeMapper.query_gradeID_resources_stats();
		List<String> name = new ArrayList<String>();
		List<String> num = new ArrayList<String>();
		for (Map<String, Object> map : list) {
			name.add(map.get("GradeID").toString());
			num.add(map.get("avg_resources").toString());
		}
		result.put("name", name);
		result.put("num", num);
		return result;
	}

	@Override
	public List<Map<String, Object>> query_word_num() {
		List<Map<String, Object>> list = realTimeMapper.query_word_num();
		List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> wind = new HashMap<String, Object>();
			wind.put("name", map.get("word"));
			wind.put("value", map.get("num"));
			result.add(wind);
		}
		return result;
	}
}
